﻿

/* map-view.js */
Exhibit.MapView=function(C,B){Exhibit.MapView._initialize();
this._div=C;
this._uiContext=B;
this._settings={};
this._accessors={getProxy:function(F,E,D){D(F);
},getColorKey:null,getSizeKey:null,getIconKey:null,getIcon:null};
this._colorCoder=null;
this._sizeCoder=null;
this._iconCoder=null;
this._selectListener=null;
this._itemIDToMarker={};
var A=this;
this._listener={onItemsChanged:function(){A._reconstruct();
}};
B.getCollection().addListener(this._listener);
};
Exhibit.MapView._settingSpecs={"center":{type:"float",defaultValue:[20,0],dimensions:2},"zoom":{type:"float",defaultValue:2},"size":{type:"text",defaultValue:"small"},"scaleControl":{type:"boolean",defaultValue:true},"overviewControl":{type:"boolean",defaultValue:false},"type":{type:"enum",defaultValue:"normal",choices:["normal","satellite","hybrid"]},"bubbleTip":{type:"enum",defaultValue:"top",choices:["top","bottom"]},"mapHeight":{type:"int",defaultValue:400},"mapConstructor":{type:"function",defaultValue:null},"color":{type:"text",defaultValue:"#FF9000"},"colorCoder":{type:"text",defaultValue:null},"sizeCoder":{type:"text",defaultValue:null},"iconCoder":{type:"text",defaultValue:null},"selectCoordinator":{type:"text",defaultValue:null},"iconSize":{type:"int",defaultValue:0},"iconFit":{type:"text",defaultValue:"smaller"},"iconScale":{type:"float",defaultValue:1},"iconOffsetX":{type:"float",defaultValue:0},"iconOffsetY":{type:"float",defaultValue:0},"shape":{type:"text",defaultValue:"circle"},"shapeWidth":{type:"int",defaultValue:24},"shapeHeight":{type:"int",defaultValue:24},"shapeAlpha":{type:"float",defaultValue:0.7},"pin":{type:"boolean",defaultValue:true},"pinHeight":{type:"int",defaultValue:6},"pinWidth":{type:"int",defaultValue:6},"sizeLegendLabel":{type:"text",defaultValue:null},"colorLegendLabel":{type:"text",defaultValue:null},"iconLegendLabel":{type:"text",defaultValue:null},"markerScale":{type:"text",defaultValue:null},"showHeader":{type:"boolean",defaultValue:true},"showSummary":{type:"boolean",defaultValue:true},"showFooter":{type:"boolean",defaultValue:true}};
Exhibit.MapView._accessorSpecs=[{accessorName:"getProxy",attributeName:"proxy"},{accessorName:"getLatlng",alternatives:[{bindings:[{attributeName:"latlng",types:["float","float"],bindingNames:["lat","lng"]},{attributeName:"maxAutoZoom",type:"float",bindingName:"maxAutoZoom",optional:true}]},{bindings:[{attributeName:"lat",type:"float",bindingName:"lat"},{attributeName:"lng",type:"float",bindingName:"lng"},{attributeName:"maxAutoZoom",type:"float",bindingName:"maxAutoZoom",optional:true}]}]},{accessorName:"getColorKey",attributeName:"marker",type:"text"},{accessorName:"getColorKey",attributeName:"colorKey",type:"text"},{accessorName:"getSizeKey",attributeName:"sizeKey",type:"text"},{accessorName:"getIconKey",attributeName:"iconKey",type:"text"},{accessorName:"getIcon",attributeName:"icon",type:"url"}];
Exhibit.MapView._initialize=function(){var B=[];
var F=document.documentElement.getElementsByTagName("head");
for(var C=0;
C<F.length;
C++){var E=F[C].getElementsByTagName("link");
for(var A=0;
A<E.length;
A++){var D=E[A];
if(D.rel.match(/\bexhibit\/map-painter\b/)){Exhibit.MapView._markerUrlPrefix=D.href+"?";
}}}Exhibit.MapView._initialize=function(){};
};
Exhibit.MapView.create=function(D,C,B){var A=new Exhibit.MapView(C,Exhibit.UIContext.create(D,B));
Exhibit.MapView._configure(A,D);
A._internalValidate();
A._initializeUI();
return A;
};
Exhibit.MapView.createFromDOM=function(D,C,B){var E=Exhibit.getConfigurationFromDOM(D);
var A=new Exhibit.MapView(C!=null?C:D,Exhibit.UIContext.createFromDOM(D,B));
Exhibit.SettingsUtilities.createAccessorsFromDOM(D,Exhibit.MapView._accessorSpecs,A._accessors);
Exhibit.SettingsUtilities.collectSettingsFromDOM(D,Exhibit.MapView._settingSpecs,A._settings);
Exhibit.MapView._configure(A,E);
A._internalValidate();
A._initializeUI();
return A;
};
Exhibit.MapView._configure=function(A,C){Exhibit.SettingsUtilities.createAccessors(C,Exhibit.MapView._accessorSpecs,A._accessors);
Exhibit.SettingsUtilities.collectSettings(C,Exhibit.MapView._settingSpecs,A._settings);
var B=A._accessors;
A._getLatlng=function(F,E,D){B.getProxy(F,E,function(G){B.getLatlng(G,E,D);
});
};
};
Exhibit.MapView.lookupLatLng=function(H,J,A,F,I,B){if(B==undefined){B=4;
}var G=Exhibit.ExpressionParser.parse(J);
var D=[];
H.visit(function(M){var L=G.evaluateSingle({"value":M},{"value":"item"},"value",I).value;
if(L!=null){D.push({item:M,address:L});
}});
var E=[];
var C=new GClientGeocoder();
var K=function(){if(D.length>0){var L=D.shift();
C.getLocations(L.address,function(O){if("Placemark" in O){O.Placemark.sort(function(S,R){return R.AddressDetails.Accuracy-S.AddressDetails.Accuracy;
});
}if("Placemark" in O&&O.Placemark.length>0&&O.Placemark[0].AddressDetails.Accuracy>=B){var P=O.Placemark[0].Point.coordinates;
var Q=P[1];
var N=P[0];
E.push("\t{ id: '"+L.item+"', "+A+": '"+Q+","+N+"' }");
}else{var M=L.address.split(",");
if(M.length==1){E.push("\t{ id: '"+L.item+"' }");
}else{L.address=M.slice(1).join(",").replace(/^\s+/,"");
D.unshift(L);
}}K();
});
}else{F.value=E.join(",\n");
}};
K();
};
Exhibit.MapView.prototype.dispose=function(){this._uiContext.getCollection().removeListener(this._listener);
this._map=null;
if(this._selectListener!=null){this._selectListener.dispose();
this._selectListener=null;
}this._itemIDToMarker={};
this._toolboxWidget.dispose();
this._toolboxWidget=null;
this._dom.dispose();
this._dom=null;
this._uiContext.dispose();
this._uiContext=null;
this._div.innerHTML="";
this._div=null;
GUnload();
};
Exhibit.MapView.prototype._internalValidate=function(){var B=this._uiContext.getExhibit();
if(this._accessors.getColorKey!=null){if(this._settings.colorCoder!=null){this._colorCoder=B.getComponent(this._settings.colorCoder);
}if(this._colorCoder==null){this._colorCoder=new Exhibit.DefaultColorCoder(this._uiContext);
}}if(this._accessors.getSizeKey!=null){if(this._settings.sizeCoder!=null){this._sizeCoder=B.getComponent(this._settings.sizeCoder);
if("markerScale" in this._settings){this._sizeCoder._settings.markerScale=this._settings.markerScale;
}}}if(this._accessors.getIconKey!=null){if(this._settings.iconCoder!=null){this._iconCoder=B.getComponent(this._settings.iconCoder);
}}if("selectCoordinator" in this._settings){var C=B.getComponent(this._settings.selectCoordinator);
if(C!=null){var A=this;
this._selectListener=C.addListener(function(D){A._select(D);
});
}}};
Exhibit.MapView.prototype._initializeUI=function(){var B=this;
var C=this._settings;
var D={};
D.colorGradient=(this._colorCoder!=null&&"_gradientPoints" in this._colorCoder);
D.colorMarkerGenerator=function(F){var E=C.shape;
return SimileAjax.Graphics.createTranslucentImage(Exhibit.MapView._markerUrlPrefix+"?renderer=map-marker&shape="+E+"&width=20&height=20&pinHeight=5&background="+F.substr(1),"middle");
};
D.sizeMarkerGenerator=function(E){var F=C.shape;
return SimileAjax.Graphics.createTranslucentImage(Exhibit.MapView._markerUrlPrefix+"?renderer=map-marker&shape="+F+"&width="+E+"&height="+E+"&pinHeight=0","middle");
};
D.iconMarkerGenerator=function(E){elmt=document.createElement("img");
elmt.src=E;
elmt.style.verticalAlign="middle";
elmt.style.height="40px";
return elmt;
};
this._div.innerHTML="";
this._dom=Exhibit.ViewUtilities.constructPlottingViewDom(this._div,this._uiContext,this._settings.showSummary&&this._settings.showHeader,{onResize:function(){B._map.checkResize();
}},D);
this._toolboxWidget=Exhibit.ToolboxWidget.createFromDOM(this._div,this._div,this._uiContext);
var A=this._dom.plotContainer;
A.style.height=C.mapHeight+"px";
A.className="exhibit-mapView-map";
var C=this._settings;
if(C._mapConstructor!=null){this._map=C._mapConstructor(A);
}else{this._map=new GMap2(A);
this._map.enableDoubleClickZoom();
this._map.enableContinuousZoom();
this._map.setCenter(new GLatLng(C.center[0],C.center[1]),C.zoom);
this._map.addControl(C.size=="small"?new GSmallMapControl():new GLargeMapControl());
if(C.overviewControl){this._map.addControl(new GOverviewMapControl);
}if(C.scaleControl){this._map.addControl(new GScaleControl());
}this._map.addControl(new GMapTypeControl());
switch(C.type){case"normal":this._map.setMapType(G_NORMAL_MAP);
break;
case"satellite":this._map.setMapType(G_SATELLITE_MAP);
break;
case"hybrid":this._map.setMapType(G_HYBRID_MAP);
break;
}}this._reconstruct();
};
Exhibit.MapView.prototype._reconstruct=function(){var G=this;
var W=this._uiContext.getCollection();
var Z=this._uiContext.getDatabase();
var h=this._settings;
var j=this._accessors;
var J=W.countAllItems();
var M=W.countRestrictedItems();
var H=[];
this._map.clearOverlays();
this._dom.legendWidget.clear();
this._itemIDToMarker={};
if(M>0){var Q=W.getRestrictedItems();
var a={};
var L=(this._accessors.getColorKey!=null);
var O=(this._accessors.getSizeKey!=null);
var C=(this._accessors.getIconKey!=null);
var l=(this._accessors.getIcon!=null);
Q.visit(function(k){var i=[];
G._getLatlng(k,Z,function(n){if(n!=null&&"lat" in n&&"lng" in n){i.push(n);
}});
if(i.length>0){var s=null;
if(L){s=new Exhibit.Set();
j.getColorKey(k,Z,function(n){s.add(n);
});
}var p=null;
if(O){p=new Exhibit.Set();
j.getSizeKey(k,Z,function(n){p.add(n);
});
}var r=null;
if(C){r=new Exhibit.Set();
j.getIconKey(k,Z,function(n){r.add(n);
});
}for(var o=0;
o<i.length;
o++){var m=i[o];
var t=m.lat+","+m.lng;
if(t in a){var q=a[t];
q.items.push(k);
if(L){q.colorKeys.addSet(s);
}if(O){q.sizeKeys.addSet(p);
}if(C){q.iconKeys.addSet(r);
}}else{var q={latlng:m,items:[k]};
if(L){q.colorKeys=s;
}if(O){q.sizeKeys=p;
}if(C){q.iconKeys=r;
}a[t]=q;
}}}else{H.push(k);
}});
var X={mixed:false,missing:false,others:false,keys:new Exhibit.Set()};
var T={mixed:false,missing:false,others:false,keys:new Exhibit.Set()};
var F={mixed:false,missing:false,others:false,keys:new Exhibit.Set()};
var U,P=Infinity;
var B=function(n){var i=n.items.length;
if(!U){U=new GLatLngBounds();
}var o=G._settings.shape;
var k=G._settings.color;
if(L){k=G._colorCoder.translateSet(n.colorKeys,X);
}var p=G._settings.iconSize;
if(O){p=G._sizeCoder.translateSet(n.sizeKeys,T);
}var q=null;
if(i==1){if(l){j.getIcon(n.items[0],Z,function(t){q=t;
});
}}if(C){q=G._iconCoder.translateSet(n.iconKeys,F);
}var q=Exhibit.MapView._makeIcon(o,k,p,i==1?"":i.toString(),q,G._settings);
var s=new GLatLng(n.latlng.lat,n.latlng.lng);
var m=new GMarker(s,q);
if(P>n.latlng.maxAutoZoom){P=n.latlng.maxAutoZoom;
}U.extend(s);
GEvent.addListener(m,"click",function(){m.openInfoWindow(G._createInfoWindow(n.items));
if(G._selectListener!=null){G._selectListener.fire({itemIDs:n.items});
}});
G._map.addOverlay(m);
for(var r=0;
r<n.items.length;
r++){G._itemIDToMarker[n.items[r]]=m;
}};
for(var g in a){B(a[g]);
}if(L){var V=this._dom.legendWidget;
var f=this._colorCoder;
var R=X.keys.toArray().sort();
if(h.colorLegendLabel!==null){V.addLegendLabel(h.colorLegendLabel,"color");
}if(f._gradientPoints!=null){var K=this._dom.legendWidget;
K.addGradient(this._colorCoder._gradientPoints);
}else{for(var c=0;
c<R.length;
c++){var N=R[c];
var S=f.translate(N);
V.addEntry(S,N);
}}if(X.others){V.addEntry(f.getOthersColor(),f.getOthersLabel());
}if(X.mixed){V.addEntry(f.getMixedColor(),f.getMixedLabel());
}if(X.missing){V.addEntry(f.getMissingColor(),f.getMissingLabel());
}}if(O){var V=this._dom.legendWidget;
var D=this._sizeCoder;
var R=T.keys.toArray().sort();
if(h.sizeLegendLabel!==null){V.addLegendLabel(h.sizeLegendLabel,"size");
}if(D._gradientPoints!=null){var Y=D._gradientPoints;
var e=(Y[Y.length-1].value-Y[0].value)/5;
R=[];
for(var d=0;
d<6;
d++){R.push(Math.floor(Y[0].value+e*d));
}for(var c=0;
c<R.length;
c++){var N=R[c];
var E=D.translate(N);
V.addEntry(E,N,"size");
}}else{for(var c=0;
c<R.length;
c++){var N=R[c];
var E=D.translate(N);
V.addEntry(E,N,"size");
}if(T.others){V.addEntry(D.getOthersSize(),D.getOthersLabel(),"size");
}if(T.mixed){V.addEntry(D.getMixedSize(),D.getMixedLabel(),"size");
}if(T.missing){V.addEntry(D.getMissingSize(),D.getMissingLabel(),"size");
}}}if(C){var V=this._dom.legendWidget;
var A=this._iconCoder;
var R=F.keys.toArray().sort();
if(h.iconLegendLabel!=null){V.addLegendLabel(h.iconLegendLabel,"icon");
}for(var c=0;
c<R.length;
c++){var N=R[c];
var I=A.translate(N);
V.addEntry(I,N,"icon");
}if(F.others){V.addEntry(A.getOthersIcon(),A.getOthersLabel(),"icon");
}if(F.mixed){V.addEntry(A.getMixedIcon(),A.getMixedLabel(),"icon");
}if(F.missing){V.addEntry(A.getMissingIcon(),A.getMissingLabel(),"icon");
}}if(U&&typeof h.zoom=="undefined"){var b=Math.max(0,G._map.getBoundsZoomLevel(U)-1);
b=Math.min(b,P,h.maxAutoZoom);
G._map.setZoom(b);
}if(U&&typeof h.center=="undefined"){G._map.setCenter(U.getCenter());
}}this._dom.setUnplottableMessage(M,H);
};
Exhibit.MapView.prototype._select=function(B){var C=B.itemIDs[0];
var A=this._itemIDToMarker[C];
if(A){A.openInfoWindow(this._createInfoWindow([C]));
}};
Exhibit.MapView.prototype._createInfoWindow=function(A){return Exhibit.ViewUtilities.fillBubbleWithItems(null,A,this._uiContext);
};
Exhibit.MapView._iconData=null;
Exhibit.MapView._markerUrlPrefix="http://simile.mit.edu/painter/painter?";
Exhibit.MapView._defaultMarkerShape="circle";
Exhibit.MapView._makeIcon=function(L,G,M,O,K,E){var D=O.length*3;
var I=Math.ceil(E.shapeWidth/2)+D;
var Q=E.shapeHeight;
var B=I*2;
var P=Q;
if(M>0){B=M;
I=Math.ceil(M/2);
P=M;
Q=M;
E.pin=false;
}var N=new GIcon();
var H=["renderer=map-marker","shape="+L,"alpha="+E.shapeAlpha,"width="+B,"height="+Q,"background="+G.substr(1),"label="+O];
var A=["renderer=map-marker-shadow","shape="+L,"width="+B,"height="+Q];
var J=[];
if(K!=null){H.push("icon="+K);
if(E.iconFit!="smaller"){H.push("iconFit="+E.iconFit);
}if(E.iconScale!=1){H.push("iconScale="+E.iconScale);
}if(E.iconOffsetX!=1){H.push("iconX="+E.iconOffsetX);
}if(E.iconOffsetY!=1){H.push("iconY="+E.iconOffsetY);
}}if(E.pin){var F=E.pinHeight;
var C=Math.ceil(E.pinWidth/2);
P+=F;
J.push("pinHeight="+F);
J.push("pinWidth="+(C*2));
N.iconAnchor=new GPoint(I,P);
N.imageMap=[0,0,0,Q,I-C,Q,I,P,I+C,Q,B,Q,B,0];
N.shadowSize=new GSize(B*1.5,P-2);
N.infoWindowAnchor=(E.bubbleTip=="bottom")?new GPoint(I,P):new GPoint(I,0);
}else{J.push("pin=false");
N.iconAnchor=new GPoint(I,Math.ceil(P/2));
N.imageMap=[0,0,0,Q,B,Q,B,0];
N.infoWindowAnchor=new GPoint(I,0);
}N.image=Exhibit.MapView._markerUrlPrefix+H.concat(J).join("&")+"&.png";
if(M==0){N.shadow=Exhibit.MapView._markerUrlPrefix+A.concat(J).join("&")+"&.png";
}N.iconSize=new GSize(B,P);
N.shadowSize=new GSize(B*1.5,P-2);
return N;
};


/* vemap-view.js */
Exhibit.VEMapView=function(C,B){this._div=C;
this._uiContext=B;
this._settings={};
this._accessors={getProxy:function(F,E,D){D(F);
},getColorKey:null,getIcon:null};
this._colorCoder=null;
var A=this;
this._listener={onItemsChanged:function(){A._reconstruct();
}};
B.getCollection().addListener(this._listener);
};
Exhibit.VEMapView._id=1;
Exhibit.VEMapView._settingSpecs={"center":{type:"float",defaultValue:[20,0],dimensions:2},"zoom":{type:"float",defaultValue:2},"size":{type:"text",defaultValue:"small"},"scaleControl":{type:"boolean",defaultValue:true},"overviewControl":{type:"boolean",defaultValue:false},"type":{type:"enum",defaultValue:"normal",choices:["normal","satellite","hybrid"]},"bubbleTip":{type:"enum",defaultValue:"top",choices:["top","bottom"]},"mapHeight":{type:"int",defaultValue:400},"mapConstructor":{type:"function",defaultValue:null},"color":{type:"text",defaultValue:"#FF9000"},"colorCoder":{type:"text",defaultValue:null},"iconScale":{type:"float",defaultValue:1},"iconOffsetX":{type:"float",defaultValue:0},"iconOffsetY":{type:"float",defaultValue:0},"shape":{type:"text",defaultValue:"circle"},"bodyWidth":{type:"int",defaultValue:24},"bodyHeight":{type:"int",defaultValue:24},"pin":{type:"boolean",defaultValue:true},"pinHeight":{type:"int",defaultValue:6},"pinWidth":{type:"int",defaultValue:6}};
Exhibit.VEMapView._accessorSpecs=[{accessorName:"getProxy",attributeName:"proxy"},{accessorName:"getLatlng",alternatives:[{bindings:[{attributeName:"latlng",types:["float","float"],bindingNames:["lat","lng"]},{attributeName:"maxAutoZoom",type:"float",bindingName:"maxAutoZoom",optional:true}]},{bindings:[{attributeName:"lat",type:"float",bindingName:"lat"},{attributeName:"lng",type:"float",bindingName:"lng"},{attributeName:"maxAutoZoom",type:"float",bindingName:"maxAutoZoom",optional:true}]}]},{accessorName:"getColorKey",attributeName:"marker",type:"text"},{accessorName:"getColorKey",attributeName:"colorKey",type:"text"},{accessorName:"getIcon",attributeName:"icon",type:"url"}];
Exhibit.VEMapView.create=function(D,C,B){var A=new Exhibit.VEMapView(C,Exhibit.UIContext.create(D,B));
Exhibit.VEMapView._configure(A,D);
A._internalValidate();
A._initializeUI();
return A;
};
Exhibit.VEMapView.createFromDOM=function(D,C,B){var E=Exhibit.getConfigurationFromDOM(D);
var A=new Exhibit.VEMapView(C!=null?C:D,Exhibit.UIContext.createFromDOM(D,B));
Exhibit.SettingsUtilities.createAccessorsFromDOM(D,Exhibit.VEMapView._accessorSpecs,A._accessors);
Exhibit.SettingsUtilities.collectSettingsFromDOM(D,Exhibit.VEMapView._settingSpecs,A._settings);
Exhibit.VEMapView._configure(A,E);
A._internalValidate();
A._initializeUI();
return A;
};
Exhibit.VEMapView._configure=function(A,C){Exhibit.SettingsUtilities.createAccessors(C,Exhibit.VEMapView._accessorSpecs,A._accessors);
Exhibit.SettingsUtilities.collectSettings(C,Exhibit.VEMapView._settingSpecs,A._settings);
var B=A._accessors;
A._getLatlng=function(F,E,D){B.getProxy(F,E,function(G){B.getLatlng(G,E,D);
});
};
};
Exhibit.VEMapView.prototype.dispose=function(){this._uiContext.getCollection().removeListener(this._listener);
this._map=null;
this._toolboxWidget.dispose();
this._toolboxWidget=null;
this._dom.dispose();
this._dom=null;
this._uiContext.dispose();
this._uiContext=null;
this._div.innerHTML="";
this._div=null;
};
Exhibit.VEMapView.prototype._internalValidate=function(){if("getColorKey" in this._accessors){if("colorCoder" in this._settings){this._colorCoder=this._uiContext.getExhibit().getComponent(this._settings.colorCoder);
}if(this._colorCoder==null){this._colorCoder=new Exhibit.DefaultColorCoder(this._uiContext);
}}};
Exhibit.VEMapView.prototype._initializeUI=function(){var B=this;
var C=this._settings;
var D="_gradientPoints" in this._colorCoder?"gradient":{markerGenerator:function(F){var E="square";
return SimileAjax.Graphics.createTranslucentImage(Exhibit.MapView._markerUrlPrefix+"?renderer=map-marker&shape="+Exhibit.MapView._defaultMarkerShape+"&width=20&height=20&pinHeight=0&background="+F.substr(1),"middle");
}};
this._div.innerHTML="";
this._dom=Exhibit.ViewUtilities.constructPlottingViewDom(this._div,this._uiContext,true,{},D);
this._toolboxWidget=Exhibit.ToolboxWidget.createFromDOM(this._div,this._div,this._uiContext);
var A=this._dom.plotContainer;
A.style.height=C.mapHeight+"px";
A.className="exhibit-mapView-map";
A.style.position="relative";
A.id="map-"+Exhibit.VEMapView._id++;
var C=this._settings;
if(C._mapConstructor!=null){this._map=C._mapConstructor(A);
}else{this._map=new VEMap(A.id);
this._map.LoadMap(new VELatLong(C.center[0],C.center[1]),C.zoom);
}this._reconstruct();
};
Exhibit.VEMapView.prototype._reconstruct=function(){var L=this;
var K=this._uiContext.getCollection();
var J=this._uiContext.getDatabase();
var T=this._settings;
var V=this._accessors;
var A=K.countAllItems();
var B=K.countRestrictedItems();
var M=[];
this._map.DeleteAllShapeLayers();
this._dom.legendWidget.clear();
if(B>0){var D=K.getRestrictedItems();
var U={};
var F=(this._accessors.getColorKey!=null);
var N=(this._accessors.getIcon!=null);
D.visit(function(b){var X=[];
L._getLatlng(b,J,function(e){if(e!=null&&"lat" in e&&"lng" in e){X.push(e);
}});
if(X.length>0){var Z=null;
if(F){Z=new Exhibit.Set();
V.getColorKey(b,J,function(e){Z.add(e);
});
}for(var d=0;
d<X.length;
d++){var c=X[d];
var Y=c.lat+","+c.lng;
if(Y in U){var a=U[Y];
a.items.push(b);
if(F){a.colorKeys.addSet(Z);
}}else{var a={latlng:c,items:[b]};
if(F){a.colorKeys=Z;
}U[Y]=a;
}}}else{M.push(b);
}});
var H={mixed:false,missing:false,others:false,keys:new Exhibit.Set()};
var G,E=Infinity;
var O=function(a){var X=a.items.length;
var c=L._settings.shape;
var Y=L._settings.color;
if(F){Y=L._colorCoder.translateSet(a.colorKeys,H);
}var d=null;
if(X==1){if(N){V.getIcon(a.items[0],J,function(h){d=h;
});
}}var d=Exhibit.VEMapView._makeIcon(c,Y,X==1?"":X.toString(),d,L._settings);
var b=new VEShapeLayer();
var f=new VELatLong(a.latlng.lat,a.latlng.lng);
var Z=new VEShape(VEShapeType.Pushpin,f);
var e=a.items[0];
var g=L._createDescription(a.items);
Z.SetCustomIcon(d);
Z.SetTitle(e);
Z.SetDescription(g);
Z.SetIconAnchor(f);
L._map.AddShapeLayer(b);
b.AddShape(Z);
};
for(var C in U){O(U[C]);
}if(F){var S=this._dom.legendWidget;
var R=this._colorCoder;
var I=H.keys.toArray().sort();
if(this._colorCoder._gradientPoints!=null){S.addGradient(this._colorCoder._gradientPoints);
}else{for(var Q=0;
Q<I.length;
Q++){var W=I[Q];
var P=R.translate(W);
S.addEntry(P,W);
}}if(H.others){S.addEntry(R.getOthersColor(),R.getOthersLabel());
}if(H.mixed){S.addEntry(R.getMixedColor(),R.getMixedLabel());
}if(H.missing){S.addEntry(R.getMissingColor(),R.getMissingLabel());
}}}this._dom.setUnplottableMessage(B,M);
};
Exhibit.VEMapView.prototype._createDescription=function(B){var C=Exhibit.ViewUtilities.fillBubbleWithItems(null,B,this._uiContext);
var A=document.createElement("div");
A.appendChild(C);
return A.innerHTML;
};
Exhibit.VEMapView._iconData=null;
Exhibit.VEMapView._markerUrlPrefix="http://simile.mit.edu/painter/painter?";
Exhibit.VEMapView._defaultMarkerShape="circle";
Exhibit.VEMapView._makeIcon=function(K,F,M,J,D){var C=M.length*3;
var H=Math.ceil(D.bodyWidth/2)+C;
var O=D.bodyHeight;
var A=H*2;
var N=O;
var L=new VECustomIconSpecification;
var G=["renderer=map-marker","shape="+K,"width="+A,"height="+O,"background="+F.substr(1),"label="+M];
var I=[];
if(J!=null){G.push("icon="+J);
if(D.iconScale!=1){G.push("iconScale="+D.iconScale);
}if(D.iconOffsetX!=1){G.push("iconX="+D.iconOffsetX);
}if(D.iconOffsetY!=1){G.push("iconY="+D.iconOffsetY);
}}if(D.pin){var E=D.pinHeight;
var B=Math.ceil(D.pinWidth/4);
N+=E;
I.push("pinHeight="+E);
I.push("pinWidth="+(B*2));
}else{I.push("pin=false");
}L.TextContent=" ";
L.Image=Exhibit.MapView._markerUrlPrefix+G.concat(I).join("&");
L.ImageHeight=N;
L.ImageWidth=A;
return L;
};
